<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>cookie高级封装</title>
</head>
<body>
    <script>
        function setCookie(name,value,options){
            // options是默认值
            options=options||{};
            if(typeof options.expires==="number"){
                var d=new Date();
                d.setDate(d.getDate()+options.expires);
            }
            return document.cookie=[
                name+"="+value,
                typeof options.expires==="number"?";expires="+d:"",
                typeof options.domain==="string"?";domain"+options.domain:"",


            ].join("");
        }
        setCookie("nihao","hello",{
            domain:"localhost"
        })
    </script>
</body>
</html>